package com.ygo.feihua.fragment;

import android.os.*;
import android.support.v4.app.*;
import android.view.*;
import com.ygo.feihua.*;
import android.widget.*;
import android.view.View.*;
import android.content.*;
import java.io.*;
import com.ygo.feihua.util.*;

public class FragmentZsZip extends Fragment
{
	TextView fz_path;
	Button fz_xz;

	private ZhutiShangchuan zs;
	Gongju gj;
	DialogUtils du;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
	{
		View v=inflater.inflate(R.layout.fragment_zs_zip,null);
		
		gj=Gongju.getdx(getActivity());
		du=DialogUtils.getdx(getActivity());
		fz_path=(TextView) v.findViewById(R.id.fz_path);
		
		fz_xz=(Button) v.findViewById(R.id.fz_xz);
		
		fz_xz.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					startActivityForResult(new Intent(getActivity(),NewWjxz.class).putExtra("lx",NewWjxz.TYPE_ZIP),0);
					
					// TODO: Implement this method
				}
			});
		
		 zs=(ZhutiShangchuan) getActivity();
		Button zs_next=zs.sc_sc;
		zs_next.setText("下一步");
		zs_next.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					if(zs.path_zt!=null&&zs.zt_size!=0){
					zs.fragmentManager.beginTransaction().replace(R.id.sc_frage, zs.fagzs).commit();

					}else{
						gj.show("请选择主题包");
					}
					// TODO: Implement this method
				}
			});
		
		
		// TODO: Implement this method
		return v;
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		// TODO: Implement this method
		super.onActivityResult(requestCode, resultCode, data);
		if(resultCode==NewWjxz.TYPE_ZIP){
			final String pa=data.getStringExtra("path");
			du.dialogj1(false,"","检查主题包中,请稍等");
			
			new Thread(new Runnable(){

					@Override
					public void run()
					{
						String ss=gj.ztJiancha(pa);
						Message me=new Message();
						me.obj=new String[]{ss,pa};
						me.what=0;
						han.sendMessage(me);
						// TODO: Implement this method
					}
				}).start();
			
			
		}
	}
	
	
	Handler han=new Handler(){

		@Override
		public void handleMessage(Message msg)
		{
			// TODO: Implement this method
			super.handleMessage(msg);
			switch(msg.what){
				case 0:
					du.dis();
					String[] s=(String[]) msg.obj;
					String ss=s[0];
					String pa=s[1];
					
					if(ss.equals("")){
						fz_path.setText("已选择主题包"+pa);
						zs.path_zt=pa;
						zs.zt_size=(int)new File(pa).length();
					}else{
				
						View[] v=du.dialogt1(true,"主题包格式错误",ss);
						Button b1=(Button) v[0];
						b1.setOnClickListener(new OnClickListener(){

								@Override
								public void onClick(View p1)
								{
									du.dis();
									// TODO: Implement this method
								}
							});
					}
					break;
				
			}
			
			
		}
		
		
		
	};

	
}
